<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form size="small" label-width="100px">
            <el-form-item label="时间选择：" class="width100">
              <el-radio-group
                v-model="tableFrom.date"
                type="button"
                class="mr20"
                size="small"
                @change="selectChange(tableFrom.date)"
              >
                <el-radio-button
                  v-for="(item, i) in fromList.fromTxt"
                  :key="i"
                  :label="item.val"
                  >{{ item.text }}</el-radio-button
                >
              </el-radio-group>
              <el-date-picker
                v-model="timeVal"
                value-format="yyyy/MM/dd"
                format="yyyy/MM/dd"
                size="small"
                type="daterange"
                placement="bottom-end"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                style="width: 250px;"
                @change="onchangeTime"
              />
            </el-form-item>
            <el-form-item label="商户名称：" style="display: inline-block;">
              <el-select
                v-model="tableFrom.mer_id"
                clearable
                filterable
                placeholder="请选择"
                class="selWidth"
                @change="getList(1), getStatisticalData()"
              >
                <el-option
                  v-for="item in merSelect"
                  :key="item.mer_id"
                  :label="item.mer_name"
                  :value="item.mer_id"
                />
              </el-select>
            </el-form-item>
          </el-form>
        </div>
        <cards-data :card-lists="cardLists" />
      </div>
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="mini"
        class="table"
        highlight-current-row
      >
        <el-table-column label="序号" min-width="60">
          <template scope="scope">
            <span>{{
              scope.$index + (tableFrom.page - 1) * tableFrom.limit + 1
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="商户名称" min-width="150">
          <template slot-scope="scope">
            <span>{{
              scope.row.merchant ? scope.row.merchant.mer_name : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="充值金额（元）" min-width="100">
          <template slot-scope="scope">
            <span>{{
              scope.row.financial_pm === 1
                ? scope.row.number
                : -scope.row.number
            }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="支付时间" min-width="130" />
      </el-table>
      <div class="block">
        <el-pagination
          background
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import { capitalFlowLstApi, getStatisticsApi } from "@/api/accounts";
import { merSelectApi } from "@/api/product";
import { fromList } from "@/libs/constants.js";
import { roterPre } from "@/settings";
import cardsData from "@/components/cards/index";
export default {
  name: "AccountsCapitalFlow",
  components: { cardsData },
  data() {
    return {
      timeVal: [],
      merSelect: [],
      tableData: {
        data: [],
        total: 0
      },
      roterPre: roterPre,
      listLoading: true,
      tableFrom: {
        date: "",
        keyword: "",
        mer_id: "",
        page: 1,
        limit: 20
      },
      fromList: fromList,
      options: [],
      cardLists: []
    };
  },
  mounted() {
    this.getList();
    this.getStatisticalData();
    this.getMerSelect();
  },
  methods: {
    // 时间选择
    selectChange(tab) {
      this.tableFrom.date = tab;
      this.timeVal = [];
      this.tableFrom.page = 1;
      this.getList();
      this.getStatisticalData();
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e;
      this.tableFrom.date = e ? this.timeVal.join("-") : "";
      this.tableFrom.page = 1;
      this.getList();
      this.getStatisticalData();
    },
    //获取统计数据
    getStatisticalData() {
      getStatisticsApi({ date: this.tableFrom.date })
        .then(res => {
          this.cardLists = res.data;
        })
        .catch(res => {
          this.$message.error(res.message);
        });
    },
    // 商户列表；
    getMerSelect() {
      merSelectApi()
        .then(res => {
          this.merSelect = res.data;
        })
        .catch(res => {
          this.$message.error(res.message);
        });
    },
    // 列表
    getList(num) {
      this.listLoading = true;
      this.tableFrom.page = num ? num : this.tableFrom.page;
      capitalFlowLstApi(this.tableFrom)
        .then(res => {
          this.tableData.data = res.data.list;
          this.tableData.total = res.data.count;
          this.listLoading = false;
        })
        .catch(res => {
          this.$message.error(res.message);
          this.listLoading = false;
        });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList();
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList();
    }
  }
};
</script>

<style scoped></style>
